﻿#include "QCefDownFavicon.h"
#include "QCefDelegate.h"

QCefDownFavicon::QCefDownFavicon(QCefClient::DelegatePtr delegate)
    : m_delegate(delegate)
{
    QCEF_DEBUG();
}

QCefDownFavicon::QCefDownFavicon(CefRefPtr<QCefDelegate> gate)
    : m_gate(gate)
{
    QCEF_DEBUG();

    m_delegate.storeRelease(m_gate.get());
}

void QCefDownFavicon::OnDownloadImageFinished(const CefString & image_url,
                                            int http_status_code,
                                            CefRefPtr<CefImage> image)
{
    QCEF_DEBUG();

    QCefDelegate* delegate = m_delegate.loadAcquire();
    if (delegate != nullptr && image != nullptr && m_gate != nullptr)
    {
        delegate->OnFaviconChange(image_url, http_status_code, image);
    }

    //
    m_delegate = nullptr;
}

